import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/index'
import Vuetify from 'vuetify'
import 'vuetify/dist/vuetify.min.css'
import 'material-design-icons-iconfont/dist/material-design-icons.css'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { removeAuth } from '@/utils/auth'

Vue.config.productionTip = false
Vue.use(Vuetify, {
  iconfont: 'md'
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  if (store.getters.roles !== null && store.getters.roles.indexOf('admin') === -1) {
    removeAuth()
    window.location.href = '/#/login'
  } else {
    next()
  }
})

router.afterEach(() => {
  NProgress.done() // finish progress bar
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
